//
//  RecommendCell.m
//  LvXi_newVersion
//
//  Created by 王敏 on 16/9/6.
//  Copyright © 2016年 SJT. All rights reserved.
//

#import "RecommendCell.h"

@interface RecommendCell()

@property(nonatomic,strong)UIImageView * productImageView;

@property(nonatomic,strong)UILabel * nameLabel;

@property(nonatomic,strong)UILabel * specLabel;

@property(nonatomic,strong)UILabel * priceLabel;

@end

@implementation RecommendCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        self.cellHeight = Sign_height(96);
        [self setBackgroundImageViewHeight:self.cellHeight];
        
        
        self.productImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
        self.productImageView.image = [UIImage imageNamed:@"localDetailIMage_1"];
        [self.contentView addSubview:self.productImageView];
        
        self.nameLabel = [UILabel labelWithTextColor:[UIColor blackColor] font:[UIFont systemFontOfSize:15]];
        self.nameLabel.numberOfLines = 3;
        self.nameLabel.textAlignment = NSTextAlignmentLeft;
        self.nameLabel.text = @"民资民资民资民资民资";
        [self.contentView addSubview:self.nameLabel];
        
        self.specLabel = [UILabel labelWithTextColor:HexColor(@"#999999") font:[UIFont systemFontOfSize:11]];
        self.specLabel.text = @"规格规格规格规格规格";
//        [self.contentView addSubview:self.specLabel];
        
        self.priceLabel = [UILabel labelWithTextColor:HexColor(@"#F0A228") font:[UIFont systemFontOfSize:15]];
        self.priceLabel.text = @"¥699.00";
        [self.contentView addSubview:self.priceLabel];
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
    self.productImageView.size = CGSizeMake(self.cellHeight-2*globalMargin, self.cellHeight-2*globalMargin);
    self.productImageView.x = 2*globalMargin;
    self.productImageView.y = globalMargin;
    
    self.nameLabel.size = [self.nameLabel.text sizeInAre:CGSizeMake(ScreenWidth - self.productImageView.width - 5*globalMargin, MAXFLOAT) font:self.nameLabel.font];
    self.nameLabel.x = self.productImageView.right + globalMargin;
    self.nameLabel.y = self.productImageView.y;
    
    self.specLabel.size = [self.specLabel.text sizeInAre:CGSizeMake(ScreenWidth - self.productImageView.width - 5*globalMargin, MAXFLOAT) font:self.specLabel.font];
    self.specLabel.x = self.nameLabel.x;
    self.specLabel.y = self.nameLabel.botton + globalMargin;
    
    self.priceLabel.size = [self.priceLabel.text sizeInAre:CGSizeMake(ScreenWidth - self.productImageView.width - 5*globalMargin, MAXFLOAT) font:self.priceLabel.font];
    self.priceLabel.x = self.specLabel.x;
    self.priceLabel.y = self.productImageView.botton - self.priceLabel.height;
}

-(void)setProduct:(Product *)product{
    _product = product;
    self.nameLabel.text = _product.name;
    self.priceLabel.text = _product.price;
    [self setNeedsLayout];
}

@end
